package com.chen.reddissondemo.ctl;

import com.chen.reddissondemo.util.DistributedRedisLock;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.io.IOException;

@RestController
public class TestController {

    @RequestMapping("/redder")
    @ResponseBody
    public String redder() throws IOException {
        String key = "test123";
        //加锁
        DistributedRedisLock.acquire(key);
        //执行具体业务逻辑
        for (int i = 0; i < 5; i++) {
            System.out.println(i);
        }
        //释放锁
        DistributedRedisLock.release(key);
        //返回结果
        return "hello";
    }
}
